using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.WizardFramework;
using VSSDKAssist.Assets.CustomPages;
using VSSDKAssist.Recipes.Common.Editors;
using VSSDKAssist.Recipes.Common.Converters;
using EnvDTE;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Enums;

namespace VSSDKAssist.Recipes.ConfigureVSPackage
{
	/// <summary>
	/// Custom page for ConfigureVSPackage recipe
	/// </summary>
	public partial class ConfigureVSPackageCP : WizardPageBase
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="ConfigureVSPackageCP"/> class.
		/// </summary>
		public ConfigureVSPackageCP()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ConfigureVSPackageCP"/> class.
		/// </summary>
		/// <param name="wizard">The <see cref="T:Microsoft.Practices.WizardFramework.WizardForm"/>that will host the new page.</param>
		public ConfigureVSPackageCP(WizardForm wizard)
			: base(wizard)
		{
			InitializeComponent();
		}

		/// <summary>
		/// Gets or sets the vs hive.
		/// </summary>
		/// <value>The vs hive.</value>
		[RecipeArgument]
		public string VSHive
		{
			get { return (string)veVSHive.Value; }
			set
			{
				if(value != null)
				{
					veVSHive.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the UI context GUID.
		/// </summary>
		/// <value>The UI context GUID.</value>
		[RecipeArgument]
		public Guid UIContextGuid
		{
			get { return (Guid)veAutoLoad.Value; }
			set
			{
				if(value != null)
				{
					veAutoLoad.TextBox.Text = value.ToString();
				}
			}
		}

		/// <summary>
		/// Gets or sets the site of the control.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.ComponentModel.ISite"></see> associated with the <see cref="T:System.Windows.Forms.Control"></see>, if any.</returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public override ISite Site
		{
			get
			{
				return base.Site;
			}
			set
			{
				base.Site = value;
				if(value != null)
				{
					this.veVSHive.BeginInit();
					this.veVSHive.ValueType = typeof(string);
					base.Site.Container.Add(veVSHive);
					this.veVSHive.EditorInstance = new VSHiveEditor();
					this.veVSHive.ConverterInstance = new VSHiveConverter();
					this.veVSHive.EndInit();

					this.veAutoLoad.BeginInit();
					this.veAutoLoad.ValueType = typeof(Guid);
					base.Site.Container.Add(veAutoLoad);
					this.veAutoLoad.EditorInstance = new UIContextGuidEditor();
					this.veAutoLoad.ConverterInstance = new UIContextGuidConverter();
					this.veAutoLoad.EndInit();
				}
			}
		}

		private void veVSHive_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			string vsHive = veVSHive.Value as string;
			DictionaryService.SetValue("VSHive", vsHive);
		}

		private void veAutoLoad_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			Guid uiContextGuid = (Guid)veAutoLoad.Value;
			DictionaryService.SetValue("UIContextGuid", uiContextGuid);
		}
	}
}